package ch.ethz.fcl.metrobuzz.data.accessibility.cost;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import ch.ethz.fcl.metrobuzz.data.MBData;
import ch.ethz.fcl.metrobuzz.data.scene.basemap.Edge;
import ch.ethz.fcl.metrobuzz.tools.MBTools;

/**
 * cost for measuring accessibility in our case, only time
 * 
 * @author Zeng Wei
 * @email zeng@arch.ethz.ch
 * 
 */
public class MBCost {
	private MBData data;
	private List<MBEdgeCost> roadCosts;
	private Map<Edge, MBEdgeCost> roadCostMap;

	public MBCost(MBData data) {
		this.data = data;

		roadCosts = new ArrayList<MBEdgeCost>();
		roadCostMap = new HashMap<Edge, MBEdgeCost>();
	}

	public void addRoadCost(Edge edge, float time, float cost) {
		MBEdgeCost roadCost = roadCostMap.get(edge);

		if (edge.getId().equals("33083"))
			MBTools.debug(
					"Edge " + edge.getId() + " dist " + edge.distance()
							+ " time " + time + " cost " + cost, true);
		
		if (roadCost == null) {
			roadCost = new MBEdgeCost(edge);
			roadCost.addCost(time, cost);
			roadCosts.add(roadCost);
			roadCostMap.put(edge, roadCost);
		} else
			roadCost.addCost(time, cost);
	}

	public MBData getData() {
		return data;
	}

	public List<MBEdgeCost> getRoadCosts() {
		return roadCosts;
	}

	public MBEdgeCost getEdgeCost(Edge edge) {
		return roadCostMap.get(edge);
	}
}
